//
//  CameraAlertViewController.m
//  xappSmartParkiOS
//
//  Created by Eason on 2018/2/3.
//  Copyright © 2018年 Alibaba. All rights reserved.
//

#import "CameraAlertViewController.h"

@interface CameraAlertViewController ()
{
    CameraAlertActionCallBack actionCallBack;
}
@end

@implementation CameraAlertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
+ (void) showAuthCameraAlert:(UIViewController*)vc callBack:(CameraAlertActionCallBack)callBack{
    CameraAlertViewController *alert=[[CameraAlertViewController alloc]initWithNibName:@"CameraAlertViewController" bundle:nil];
    [alert setCallBack:callBack];
    alert.view.frame=vc.view.bounds;
    [vc.view addSubview:alert.view];
    [vc addChildViewController:alert];
}
- (void)setCallBack:(CameraAlertActionCallBack)callBack{
    actionCallBack=callBack;
}
- (void)clean{
    actionCallBack=nil;
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}
- (IBAction)openCameraAuth:(id)sender {
    NSURL *url=[NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
    
    if (actionCallBack) {
        actionCallBack(1);
    }
}
- (IBAction)closeBtnPressed:(id)sender{
    if (actionCallBack) {
        actionCallBack(0);
    }
    [self clean];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
